package com.example.a14110100420.yuejian.WAdapter.picture;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.a14110100420.yuejian.R;
import com.example.a14110100420.yuejian.Wbean.picture.PictureDetail;
import com.example.a14110100420.yuejian.Wviewholder.picture.PictureDetailViewholder;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by wanger on 2017/10/26.
 */

public class PictureDetailAdapter extends RecyclerView.Adapter {
    private Context context;
    private List list;
    private LayoutInflater layoutInflater;

    public PictureDetailAdapter(Context context,List list) {
        this.context = context;
        this.list = list;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.picturedetail_adapter,parent,false);
        PictureDetailViewholder viewholder = new PictureDetailViewholder(view);
        return viewholder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        PictureDetailViewholder pictureDetailViewholder = (PictureDetailViewholder) holder;
        PictureDetail pictureDetail = (PictureDetail) list.get(position);

        String username = pictureDetail.getUser_name();
        String userpic = pictureDetail.getPhoto();
        String replytime = pictureDetail.getReply_time();
        String reply = pictureDetail.getReply();

        pictureDetailViewholder.user_name.setText(username);
        pictureDetailViewholder.reply_time.setText(replytime);
        pictureDetailViewholder.reply.setText(reply);
        Picasso.with(context)
                .load("http://172.24.10.175/workout/Uploads/"+userpic)
                .into(pictureDetailViewholder.user_pic);
        if(pictureDetailViewholder.user_pic.getDrawable()==null){
            pictureDetailViewholder.user_pic.setImageResource(R.drawable.wutouxiang);
        }

    }

    @Override
    public int getItemCount() {

            return list.size();
    }
}
